<!DOCTYPE HTML>
<!--
	Forty by HTML5 UP
	html5up.net | @ajlkn
	Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
	<head>
		<title>添加监视商品</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
		<link rel="stylesheet" href="../assets/css/main.css" />
		<!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
		<!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
			<style>
	#imgAll{
background:rgba(0,0,0,0.5);width:100%;height:100%;position:absolute;z-index:99;left:0;top:0;display:none;
	}
	#imgAll p{
		padding-top:15px;
		color:#fff;
	}
.upPage{
		position:absolute;
		z-index: 100;
		top:100px;
		left:100px;
	}
	</style>
	</head>
	<body>
	<div id="imgAll">
		<div class="upPage">
		<p>搜索中...</p>
		</div>
	</div>
		<!-- Wrapper -->
			<div id="wrapper">




				<!-- Main -->
					<div id="main" class="alt">

						<!-- One -->
							<section id="one">
								<div class="inner">
									<header class="major">
										<h1>添加监视商品</h1>
									</header>
									<p><input type="text" id="productName"></p>
                                    <button id="search" class="btn btn-primary" onclick="search()">搜索</button>
									<p>
									    <table id="productTable"> 
											<colgroup>
												<col width='20%'></col>
												<col></col>
												<col width='10%'></col>
											 </colgroup>
											<tr>
												<td align="left">京东URL:</td>
												<td>
												  <input type="text" id="jdURL" class="form-control">	
										  
												</td>
												<td>
													<input type="checkbox" id="jdCheckbox" name="jdCheckbox">
													<label for="jdCheckbox"></label>												  
												</td>
											</tr>  
                                            <tr hidden id="jdDetail">
											</tr>
											<tr>
												<td align="left">亚马逊URL:</td>
												<td>
												  <input type="text" id="amURL" class="form-control">
												</td>
												<td>
													<input type="checkbox" id="amCheckbox" name="amCheckbox">
													<label for="amCheckbox"></label>												  
												</td>
											</tr> 
											<tr hidden="true" id="amDetail">
											</tr>
											<tr>
												<td align="left">当当URL:</td>
												<td>
												  <input type="text" id="ddURL" class="form-control">
												</td>
												<td>
													<input type="checkbox" id="ddCheckbox" name="ddCheckbox">
													<label for="ddCheckbox"></label>												  
												</td>
											</tr>
											<tr hidden="true" id="ddDetail">
											</tr> 											
                                        </table>										
									</p>
                                    <button id="addButton" class="btn btn-primary" onclick="add()">添加</button>
								</div>
							</section>

					</div>

			


			</div>

		<!-- Scripts -->
			<script src="../assets/js/jquery.min.js"></script>
			<script src="../assets/js/jquery.scrolly.min.js"></script>
			<script src="../assets/js/jquery.scrollex.min.js"></script>
			<script src="../assets/js/skel.min.js"></script>
			<script src="../assets/js/util.js"></script>
			<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
			<script src="../assets/js/main.js"></script>
            <script>
			     var url="http://118.178.142.172:80/"
				 var temp = window.location.href;
				 var code = temp.split("?")[1].split("&")[0].split("=")[1];
				 var openID ="";
				 $.ajax({
					url:url + "api/getOpenID",
					type:"POST",
					data:{"code":code},
					dataType:"JSON",
					async: false,
					success:function(data){
						openID = data.openID;
					}
				 });
				 function search(){
				    var name=$("#productName").val();
					$.ajax({
						url:url + "product/search",
						type:"POST",
						data:{"name":name},
						dataType:"JSON",
						beforeSend:function(){
						    var upPage = document.querySelector(".upPage");
							$(".upPage").css("top",window.innerHeight*0.5 + document.body.scrollTop - upPage.offsetHeight/2);
							$(".upPage").css("left",window.innerWidth*0.5 + document.body.scrollTop - upPage.offsetHeight/2);						
							$("#imgAll").css("display","block");
							$("body").css("overflow","hidden");		
						},
						complete:function(){
							$("#imgAll").css("display","none");
							$("body").css("overflow","auto");	
						},						
						success:function(data){
							var result=data.result;
							if ("amResult" in result){
							   $("#amURL").empty();
							   $("#amDetail").empty()
							   $("#amURL").val(result.amResult.url);
							   $("#amDetail").removeAttr("hidden"); 
							   $("#amDetail").append("<td colspan='3'>名称："+result.amResult.name+"<br>"+"价格："+result.amResult.price+"<br>"+"<img src='"+result.amResult.image+"'></img></td>");
							}   
							if ("jdResult" in result){
							   $("#jdURL").empty();
							   $("#jdDetail").empty()
							   $("#jdURL").val(result.jdResult.url);
							   $("#jdDetail").removeAttr("hidden"); 
							   $("#jdDetail").append("<td colspan='3'>名称："+result.jdResult.name+"<br>"+"价格："+result.jdResult.price+"<br>"+"<img src='"+result.jdResult.image+"'></img></td>");
							}   
							if ("ddResult" in result){
							   $("#ddURL").empty();
							   $("#ddDetail").empty()
							   $("#ddURL").val(result.ddResult.url);
							   $("#ddDetail").removeAttr("hidden"); 
							   $("#ddDetail").append("<td colspan='3'>名称："+result.ddResult.name+"<br>"+"价格："+result.ddResult.price+"<br>"+"<img src='"+result.ddResult.image+"'></img></td>");						   
							}
						}
				 });
				 }
				 function add(){
				    var goods = {};
					alert(openID);
					goods.openID=openID;
					goods.name =$("#productName").val();
					goods.JDURL =$("#jdURL").val();
					goods.AMURL =$("#amURL").val();
					goods.DDURL =$("#ddURL").val();
					if ($("#jdURL").val()==""||$('#jdCheckbox').is(':checked')==false) delete goods.JDURL;
					if ($("#amURL").val()==""||$('#amCheckbox').is(':checked')==false) delete goods.AMURL;
					if ($("#ddURL").val()==""||$('#ddCheckbox').is(':checked')==false) delete goods.DDURL;
					$.ajax({
						url:url + "product/addProduct",
						type:"POST",
						data:goods,
						dataType:"JSON",
						success:function(data){
							if(data.RESULT == "SUCCESS"){
								alert("添加成功");
							}
							else{
								alert("添加失败");
							}
						}
					});
	 		
	 	         }
			</script>
	</body>
</html>